# coding = utf-8

import os
import time

from django.db.models import Q
from rest_framework.generics import ListAPIView

from hshims import settings
from rest_framework import status, mixins
from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework.viewsets import ModelViewSet, ReadOnlyModelViewSet, GenericViewSet
from users.api.utils import jwt_response_payload_handler, jwt_decode_handler

from users.models import UserInfo
from .mobile_serializers import MobileUserInfoReadOnlySerializer


class MobileUserInfoReadOnlyAPIView(APIView):

    permission_classes = ()

    def get(self, request, *args, **kwargs):
        token = request.query_params.get("token")
        payload = jwt_decode_handler(token)
        user_id = payload.get("user_id")
        user = UserInfo.objects.filter(id=user_id, is_active=True).first()

        serializer = MobileUserInfoReadOnlySerializer(user, context={"request": request})
        return Response(serializer.data)
